<?php
//获取历史数据
$db = file_get_contents('ssq.csv');
$db = explode("\n",$db);

foreach($db as $k=>$v){
    $db[$k] = explode(',',$v);
}
foreach($db as $k=>$v){
    $recent1[] = $ssq1[] = $v[1];
    $recent2[] = $ssq2[] =$v[2];
    $recent3[] = $ssq3[] =$v[3];
    $recent4[] = $ssq4[] =$v[4];
    $recent5[] = $ssq5[] =$v[5];
    $recent6[] = $ssq6[] =$v[6];
    $recent7[] = $ssq7[] =$v[7];
}

//冷门、热门推荐
for($i=1;$i<=7;$i++){
    $ssq = 'ssq'.$i;
    $ssq_hot = 'ssq'.$i.'_hot';
    $ssq_cold = 'ssq'.$i.'_cold';
    $$ssq = array_count_values($$ssq);
    $$ssq_hot = array_keys($$ssq,max($$ssq));
    $$ssq_cold = array_keys($$ssq,min($$ssq));
    $cold[] = sprintf ( "%02d",$$ssq_cold[0]);
    $hot[] = sprintf ( "%02d",$$ssq_hot[0]);
}

//随机推荐
$rand=array_rand(range(1,33),6);
$rand[]=mt_rand(1,6);
foreach($rand as $k=>$v){
    $rand[$k] = sprintf ( "%02d",$v);
}

//上期开奖
$n = count($db)-1;
for($i=1;$i<=7;$i++){
    $last[] = sprintf ( "%02d",$db[$n][$i]);
}

//近期推荐
$periods = 20;
$recent1 = array_slice($recent1,-$periods);
$recent2 = array_slice($recent2,-$periods);
$recent3 = array_slice($recent3,-$periods);
$recent4 = array_slice($recent4,-$periods);
$recent5 = array_slice($recent5,-$periods);
$recent6 = array_slice($recent6,-$periods);
$recent7 = array_slice($recent7,-$periods);

//近期冷门、热门推荐
for($i=1;$i<=7;$i++){
    $recent = 'recent'.$i;
    $recent_hot = 'recent'.$i.'_hot';
    $recent_cold = 'recent'.$i.'_cold';
    $$recent = array_count_values($$recent);
    $$recent_hot = array_keys($$recent,max($$recent));
    $$recent_cold = array_keys($$recent,min($$recent));
    $recentcold[] = sprintf ( "%02d",$$recent_cold[0]);
    $recenthot[] = sprintf ( "%02d",$$recent_hot[0]);
}

//强力推荐
//长期热门短期冷门，下期要出
//长期冷门短期热门，下期不出

echo '上期开奖：'.implode(' ',$last);
echo "\r\n";
echo '长期冷门：'.implode(' ',$cold);
echo "\r\n";
echo '长期热门：'.implode(' ',$hot);
echo "\r\n";
echo '建议下注：'.implode(' ',$recenthot);
echo "\r\n";
echo '强力推荐：'.implode(' ',$recentcold);
echo "\r\n";
echo '随机推荐：'.implode(' ',$rand);
